﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using COM.Rights.Model;
using COM.Rights.BLL;
using System.Data;
using COM.PreAlarm.Model;
using COM.PreAlarm.BLL;
using System.Web.UI.WebControls;

public partial class Pages_ProductTotal_Default : AnalyticsListBase
{  
	#region 重写方法

    
     protected string _FusionCartXML = "";

    protected override void OnLoad()
    {
        
        if (!IsPostBack) {
            fromData.Text = DateTime.Now.ToString("yyyy-MM-dd");
            toData.Text = DateTime.Now.ToString("yyyy-MM-dd");

            //初始化市
            MdlistInfo _MdlistInfo = new MdlistInfo();
            _MdlistInfo.TranType = "GetCityByUser";
            _MdlistInfo.UID = ZASession.Account;

            DataTable dt = Mdlist.GetDataTableByModel(_MdlistInfo);
            if (dt != null)
            {
                if (dt.Rows.Count == 1)
                {
                    //一条记录默认选中
                    ZABinder.FillList(StringHelper.FormatObjToString(dt.Rows[0]["Name"]), ddlCity, false, dt);
                    //填充区
                    _MdlistInfo.TranType = "GetDistrictByUser";
                    _MdlistInfo.UID = ZASession.Account;
                    _MdlistInfo.Type = ddlCity.SelectedValue;
                    DataTable dtDistrict = Mdlist.GetDataTableByModel(_MdlistInfo);
                    //一条记录默认选中
                    if (dtDistrict != null && dtDistrict.Rows.Count == 1)
                    {
                        ZABinder.FillList(StringHelper.FormatObjToString(dtDistrict.Rows[0]["name"]), ddlDistrict, false, dtDistrict);
                    }
                    else
                    {
                        ZABinder.FillList(string.Empty, ddlDistrict, true, dtDistrict);
                    }

                }
                else
                {
                    ZABinder.FillList(string.Empty, ddlCity, true, dt);
                    ddlDistrict.Items.Add(new ListItem("--请选择--", ""));
                }

            }
            else
            {
                //没有市的权限，显示所管控的所有区
                ZABinder.FillList(string.Empty, ddlCity, true, dt);
                ddlDistrict.Items.Add(new ListItem("--请选择--", ""));
            }
        }

    
        base.OnLoad();
    }


    

    protected override void OnGridDataBind()
    {
        BdOrder _BdOrder = new BdOrder();
        List<DBParameter> _listDBParameter = new List<DBParameter>();
        _listDBParameter.Add(new DBParameter("@TranType", "OnLineTotal"));
        _listDBParameter.Add(new DBParameter("@OrderDateBegin", fromData.Text));
        _listDBParameter.Add(new DBParameter("@OrderDateEnd", toData.Text));
        _listDBParameter.Add(new DBParameter("@UID", ZASession.Account));
        _listDBParameter.Add(new DBParameter("@City", ddlCity.SelectedValue));
        _listDBParameter.Add(new DBParameter("@District", ddlDistrict.SelectedValue));
        _listDBParameter.Add(new DBParameter("@Equip_SimNo", txtAll.Text));
        _listDBParameter.Add(new DBParameter("@AvgTotalBegin", StringHelper.FormatObjStringToint(txtAvgBegin.Text)));
        _listDBParameter.Add(new DBParameter("@AvgTotalEnd", StringHelper.FormatObjStringToint(txtAvgEnd.Text)));

        IDataReader sdr = _BdOrder.ExecuteReader("[dbo].[report]", _listDBParameter, System.Data.CommandType.StoredProcedure);
  

        DataTable dt = new DataTable();
        dt.Load(sdr);
        dt.Columns.Add("CurrentStatus");
        string TargetDate = DateTime.Now.Hour.ToString().Length < 2 ? '0' + DateTime.Now.Hour.ToString() : DateTime.Now.Hour.ToString();
        foreach (DataRow dr in dt.Rows)
        {
            dr["CurrentStatus"] = StringHelper.FormatObjStringToint(dr["online_" + TargetDate]) == 1 ? "在线" : "离线";
        }

       
        
         BaseMainPager.RecordCount = dt.Rows.Count;
        gvInfos.DataSource = ZPager.TablePage(dt, BaseMainPager.PageSize, BaseMainPager.CurrentPageIndex);
      
        gvInfos.DataBind();
    }

    protected void ddlCity_SelectedIndexChanged(object sender, EventArgs e)
    {

        if (ddlCity.SelectedValue != string.Empty)
        {
            //初始化区
            MdlistInfo _MdlistInfo = new MdlistInfo();
            _MdlistInfo.TranType = "GetDistrictByUser";
            _MdlistInfo.UID = ZASession.Account;
            _MdlistInfo.Type = ddlCity.SelectedValue;
            ZABinder.FillList(string.Empty, ddlDistrict, true, Mdlist.GetDataTableByModel(_MdlistInfo));
        }

    }

	#endregion 	重写方法
}